//
//  OPMainHelperController.m
//  OnePiece
//
//  Created by wsy on 15/10/26.
//  Copyright © 2015年 wsy. All rights reserved.
//

#import "OPMainHelperController.h"
#import "OPHelperWeatherController.h"
#import "OPHelperView.h"
#import "OPSettingController.h"
#import "OPHelperAccountViewController.h"

#import "ParitiesController.h"

@interface OPMainHelperController ()
@property (nonatomic, strong) OPHelperView *mainView;
@end

@implementation OPMainHelperController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    _mainView = [[OPHelperView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-49)];
    [self.view addSubview:_mainView];
    [_mainView.weatherBT addTarget:self action:@selector(pushToWeather) forControlEvents:(UIControlEventTouchUpInside)];
    [_mainView.settingBT addTarget:self action:@selector(pushToSetting) forControlEvents:(UIControlEventTouchUpInside)];
    [_mainView.accountBT addTarget:self action:@selector(pushToAccount) forControlEvents:(UIControlEventTouchUpInside)];
    [_mainView.exchangeBT addTarget:self action:@selector(pushToExchange) forControlEvents:(UIControlEventTouchUpInside)];
    
    [UIView animateWithDuration:1 delay:0 options:(UIViewAnimationOptionCurveEaseInOut) animations:^{
        _mainView.accountBT.frame = CGRectMake(0, SCREEN_HEIGHT*2/5, SCREEN_WIDTH/2, SCREEN_HEIGHT*1.5/5-24);
    } completion:nil];
    [UIView animateWithDuration:1 delay:0.2 options:(UIViewAnimationOptionCurveEaseInOut) animations:^{
        _mainView.exchangeBT.frame = CGRectMake(SCREEN_WIDTH/2, SCREEN_HEIGHT*2/5, SCREEN_WIDTH/2, SCREEN_HEIGHT*1.5/5-24);
    } completion:nil];
    [UIView animateWithDuration:1 delay:0.4 options:(UIViewAnimationOptionCurveEaseInOut) animations:^{
        _mainView.weatherBT.frame = CGRectMake(0, SCREEN_HEIGHT*3.5/5-24, SCREEN_WIDTH/2, SCREEN_HEIGHT*1.5/5-24);
    } completion:nil];
    [UIView animateWithDuration:1 delay:0.6 options:(UIViewAnimationOptionCurveEaseInOut) animations:^{
        _mainView.settingBT.frame = CGRectMake(SCREEN_WIDTH/2, SCREEN_HEIGHT*3.5/5-24, SCREEN_WIDTH/2, SCREEN_HEIGHT*1.5/5-24);
    } completion:nil];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)pushToWeather{
    OPHelperWeatherController *wVC = [[OPHelperWeatherController alloc]init];
    self.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:wVC animated:YES];
    self.hidesBottomBarWhenPushed = NO;
}



- (void)pushToSetting{
    OPSettingController *sVC = [[OPSettingController alloc]init];
    self.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:sVC animated:YES];
    self.hidesBottomBarWhenPushed = NO;
}

- (void)pushToAccount
{
    OPHelperAccountViewController *accountVC = [[OPHelperAccountViewController alloc]init];
    [self.navigationController pushViewController:accountVC animated:YES];
}

- (void)pushToExchange
{
    ParitiesController *pVC = [[ParitiesController alloc]init];
    self.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:pVC animated:YES];
    self.hidesBottomBarWhenPushed = NO;
}


- (void)viewWillAppear:(BOOL)animated
{
    _mainView.accountBT.frame = CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH/2, SCREEN_HEIGHT*1.5/5-24);
    _mainView.exchangeBT.frame = CGRectMake(SCREEN_WIDTH/2, SCREEN_HEIGHT, SCREEN_WIDTH/2, SCREEN_HEIGHT*1.5/5-24);
    _mainView.weatherBT.frame = CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH/2, SCREEN_HEIGHT*1.5/5-24);
    _mainView.settingBT.frame = CGRectMake(SCREEN_WIDTH/2, SCREEN_HEIGHT, SCREEN_WIDTH/2, SCREEN_HEIGHT*1.5/5-24);
    [UIView animateWithDuration:1 delay:0 options:(UIViewAnimationOptionCurveEaseInOut) animations:^{
        _mainView.accountBT.frame = CGRectMake(0, SCREEN_HEIGHT*2/5, SCREEN_WIDTH/2, SCREEN_HEIGHT*1.5/5-24);
    } completion:nil];
    [UIView animateWithDuration:1 delay:0.2 options:(UIViewAnimationOptionCurveEaseInOut) animations:^{
        _mainView.exchangeBT.frame = CGRectMake(SCREEN_WIDTH/2, SCREEN_HEIGHT*2/5, SCREEN_WIDTH/2, SCREEN_HEIGHT*1.5/5-24);
    } completion:nil];
    [UIView animateWithDuration:1 delay:0.4 options:(UIViewAnimationOptionCurveEaseInOut) animations:^{
        _mainView.weatherBT.frame = CGRectMake(0, SCREEN_HEIGHT*3.5/5-24, SCREEN_WIDTH/2, SCREEN_HEIGHT*1.5/5-24);
    } completion:nil];
    [UIView animateWithDuration:1 delay:0.6 options:(UIViewAnimationOptionCurveEaseInOut) animations:^{
        _mainView.settingBT.frame = CGRectMake(SCREEN_WIDTH/2, SCREEN_HEIGHT*3.5/5-24, SCREEN_WIDTH/2, SCREEN_HEIGHT*1.5/5-24);
    } completion:nil];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
